package cn.com.xiaoshoujia.activities.controller;

import cn.com.xiaoshoujia.activities.dto.*;
import cn.com.xiaoshoujia.activities.service.ActivitiesService;
import cn.com.xiaoshoujia.utils.Result;
import cn.com.xiaoshoujia.utils.SALES;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;

/**
 * @author dulei
 * @Title: ActivitiesController
 * @Time 2017/8/3 10:31
 */
@RestController
public class ActivitiesController {

    Logger logger = LoggerFactory.getLogger(ActivitiesController.class);

    @Autowired
    private ActivitiesService activitiesService;

    /**
     * @Author: dulei
     * @Description: 返回拼团活动信息
     * @param: id 拼团活动ID
     * @Date: 2017/8/3 17:18
     */
    @GetMapping("team/wxTeamMsg")
    public Object findActivityMsg(Long id, HttpServletRequest request, HttpServletResponse response) {
        if (null == id) {
            logger.debug("error request");
            return SALES.encryption(request, response, new Result("FAIL", "错误请求", null));
        }
        ActivityWxTeamMsgDTO activityMsg = activitiesService.findWxActivityMsg(id);
        return SALES.encryption(request, response, new Result("SUCCESS", activityMsg));
    }

    /**
     * @Author: dulei
     * @Description: 查询团活动信息及团信息
     * @param: * @param null
     * @Date: 2017/8/7 15:10
     */
    @GetMapping("team/wxActivityMsg")
    public Object findTeamAndHead(Long id, Long headId, HttpServletRequest request, HttpServletResponse response) {
        if (null == id) {
            logger.debug("error request");
            return SALES.encryption(request, response, new Result("FAIL", "错误请求", null));
        }
        ActivityWxActivityMsgDTO activityMsg = activitiesService.findTeamAndHead(id, headId);

        return SALES.encryption(request, response, new Result("SUCCESS", activityMsg));
    }

    /**
     * @Author: dulei
     * @Description: 返回表单及团，活动状态信息
     * @Date: 2017/8/4 10:23
     */
    @GetMapping("team/wxOperation")
    public Object findOperaion(Long id, Long headId, HttpServletRequest request, HttpServletResponse response) {
        if (null == id) {
            logger.debug("error request");
            return SALES.encryption(request, response, new Result("FAIL", "错误请求", null));
        }
        ActivityOperationJsonDTO operaionJson = activitiesService.findOperaionJson(id, headId);
        if (null == operaionJson) {
            logger.debug("error response");
            return SALES.encryption(request, response, new Result("FAIL", "数据错误", null));
        }
        return SALES.encryption(request, response, new Result("SUCCESS", operaionJson));
    }

    @GetMapping("team/successMsg")
    public Object findSuccessMsg(Long id,Long headId,HttpServletRequest request, HttpServletResponse response){
        if (null==id) {
            logger.debug("error request");
            return SALES.encryption(request, response, new Result("FAIL", "错误请求", null));
        }
        ActivitySuccessDTO activitySuccessDTO = activitiesService.findSuccessMsg(id,headId);


        return SALES.encryption(request, response, new Result("SUCCESS",activitySuccessDTO));
    }
}
